package com.yiyuan.app.controller;

import com.guaike.core.entity.param.Page;
import com.guaike.core.entity.result.PageEntity;
import com.guaike.core.entity.result.Result;
import com.yiyuan.app.entity.param.AcceptInviteDTO;
import com.yiyuan.app.entity.result.InviteRecordVO;
import com.yiyuan.app.entity.result.InviteVO;
import com.yiyuan.app.service.InviteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.awt.*;
import java.io.IOException;

@RestController
@RequestMapping("/invite")
@Api(tags = "邀请相关接口组")
@AllArgsConstructor
public class InviteController {

    private final InviteService inviteService;

    @GetMapping("/myInviteConfig")
    @ApiOperation(value = "我的邀请配置信息")
    public Result<InviteVO> myInviteConfig() {
        return inviteService.myInviteConfig();
    }

    @GetMapping("/myInvitePage")
    @ApiOperation(value = "我的邀请记录列表")
    public Result<PageEntity<InviteRecordVO>> myInvitePage(@Valid Page param) {
        return inviteService.myInvitePage(param);
    }

    @PostMapping("/acceptInvite")
    @ApiOperation(value = "接受邀请")
    public Result<Boolean> acceptInvite(@RequestBody @Valid AcceptInviteDTO param) {
        return inviteService.acceptInvite(param);
    }

    @GetMapping("/downloadInviteImage")
    @ApiOperation(value = "下载邀请图片")
    public void downloadInviteImage(HttpServletResponse response) throws IOException, FontFormatException {
        inviteService.downloadInviteImage(response);
    }
}
